package com.cityfood.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cityfood.mapper.CfCardMapper;
import com.cityfood.pojo.CfCard;
import com.cityfood.pojo.CfCardExample;
import com.cityfood.pojo.CfCardExample.Criteria;
import com.cityfood.service.CardService;

@Service
public class CardServiceImpl implements CardService {
	
	@Autowired
	private CfCardMapper cardMapper;
	
	
	@Override
	public CfCard selectCardById(Integer cardId) {
		CfCard card = cardMapper.selectByPrimaryKey(cardId);
		return card;
	}

	@Override
	public List<CfCard> selectAllCardAndPage(Integer pageNum, Integer pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<CfCard> selectCardByUserId(Integer userId) {
		CfCardExample example=new CfCardExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserIdEqualTo(userId);
		List<CfCard> list = cardMapper.selectByExample(example);
		if (list.size()>0) {
			return list;
		}
		return null;
	}

	@Override
	public int insertCard(CfCard card) {
		int i = cardMapper.insertSelective(card);
		return i;
	}

	@Override
	public int updateCard(CfCard card) {
		int i = cardMapper.updateByPrimaryKeySelective(card);
		return i;
	}

	@Override
	public int deleteCard(Integer cardId) {
		int i = cardMapper.deleteByPrimaryKey(cardId);
		return i;
	}
	
	@Override 
	public CfCard selectCardByOrderId(Integer orderId){
		CfCardExample example=new CfCardExample();
		Criteria criteria = example.createCriteria();
		criteria.andOrderIdEqualTo(orderId);
		List<CfCard> list = cardMapper.selectByExample(example);
		
		if(list != null && list.size() == 1){
			return list.get(0);
		}else{
			return null;
		}
	}

}
